home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / c / avail.c < prev    next >
C/C++ Source or Header  |  1996-09-13  |  3KB  |  112 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: avail.c,v 1.4 1996/09/13 17:52:09 digulla Exp $
  4.     $Log: avail.c,v $
  5.     Revision 1.4  1996/09/13 17:52:09  digulla
  6.     Use IPTR
  7.  
  8.     Revision 1.3  1996/08/13 15:34:04  digulla
  9.     #include <exec/execbase.h> was missing
  10.  
  11.     Revision 1.2  1996/08/01 17:40:43  digulla
  12.     Added standard header for all files
  13.  
  14.     Desc:
  15.     Lang:
  16. */
  17. #include <exec/execbase.h>
  18. #include <exec/memory.h>
  19. #include <clib/exec_protos.h>
  20. #include <dos/dos.h>
  21. #include <clib/dos_protos.h>
  22. #include <utility/tagitem.h>
  23.  
  24. CALLENTRY /* Before the first symbol */
  25.  
  26. struct ExecBase *SysBase;
  27. struct DosLibrary *DOSBase;
  28.  
  29. static LONG tinymain(void);
  30.  
  31. LONG entry(struct ExecBase *sysbase)
  32. {
  33.     LONG error=RETURN_FAIL;
  34.     SysBase=sysbase;
  35.     DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",39);
  36.     if(DOSBase!=NULL)
  37.     {
  38.     error=tinymain();
  39.     CloseLibrary((struct Library *)DOSBase);
  40.     }
  41.     return error;
  42. }
  43.  
  44. static LONG tinymain(void)
  45. {
  46.     IPTR args[4]={ 0, 0, 0, 0 };
  47.     struct RDArgs *rda;
  48.     LONG error=0;
  49.  
  50.     rda=ReadArgs("CHIP/S,FAST/S,TOTAL/S,FLUSH/S",args,NULL);
  51.     if(rda!=NULL)
  52.     {
  53.     ULONG chip[4], fast[4], total[4];
  54.     if(args[0]+args[1]+args[2]>1)
  55.     {
  56.         FPuts(Output(),"Only one of CHIP, FAST or TOTAL allowed\n");
  57.         FreeArgs(rda);
  58.         return RETURN_FAIL;
  59.     }else if(args[0])
  60.     {
  61.         if(args[3])
  62.         FreeVec(AllocVec(~0ul/2,MEMF_CHIP));
  63.         chip[0]=AvailMem(MEMF_CHIP);
  64.         if(VPrintf("%ld\n",chip)<0)
  65.         error=RETURN_ERROR;
  66.     }else if(args[1])
  67.     {
  68.         if(args[3])
  69.         FreeVec(AllocVec(~0ul/2,MEMF_FAST));
  70.         fast[0]=AvailMem(MEMF_FAST);
  71.         if(VPrintf("%ld\n",fast)<0)
  72.         error=RETURN_ERROR;
  73.     }else if(args[2])
  74.     {
  75.         if(args[3])
  76.         FreeVec(AllocVec(~0ul/2,MEMF_ANY));
  77.         total[0]=AvailMem(MEMF_ANY);
  78.         if(VPrintf("%ld\n",total)<0)
  79.         error=RETURN_ERROR;
  80.     }else
  81.     {
  82.         Forbid();
  83.         if(args[3])
  84.         FreeVec(AllocVec(~0ul/2,MEMF_ANY));
  85.         chip[0]=AvailMem(MEMF_CHIP);
  86.         chip[2]=AvailMem(MEMF_CHIP|MEMF_TOTAL);
  87.         chip[3]=AvailMem(MEMF_CHIP|MEMF_LARGEST);
  88.         chip[1]=chip[2]-chip[0];
  89.         fast[0]=AvailMem(MEMF_FAST);
  90.         fast[2]=AvailMem(MEMF_FAST|MEMF_TOTAL);
  91.         fast[3]=AvailMem(MEMF_FAST|MEMF_LARGEST);
  92.         fast[1]=fast[2]-fast[0];
  93.         total[0]=AvailMem(MEMF_ANY);
  94.         total[2]=AvailMem(MEMF_ANY|MEMF_TOTAL);
  95.         total[3]=AvailMem(MEMF_ANY|MEMF_LARGEST);
  96.         total[1]=total[2]-total[0];
  97.         Permit();
  98.  
  99.         if(PutStr("Type  Available    In-Use   Maximum   Largest\n")<0||
  100.            VPrintf("chip %10.ld%10.ld%10.ld%10.ld\n",chip)<0||
  101.            VPrintf("fast %10.ld%10.ld%10.ld%10.ld\n",fast)<0||
  102.            VPrintf("total%10.ld%10.ld%10.ld%10.ld\n",total)<0)
  103.         error=RETURN_ERROR;
  104.     }
  105.     FreeArgs(rda);
  106.     }else
  107.     error=RETURN_FAIL;
  108.     if(error)
  109.     PrintFault(IoErr(),"Avail");
  110.     return error;
  111. }
  112.